<?php
/**
 * Created by PhpStorm.
 * User: zwh
 * Time: 2017-3-28 09:55:05
 */
class SceWxPayController extends BaseController {
    
    /*
     * 微信支付状态列表
     * */
    public function wx_pay_list(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
            )
        );
    
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("sce_error.login_args_error_1001");
                break;
            }
    
            //传入参数
            $token = Input::get('token');
    
            //验证token
            $engineer_data = MaintenanceEngineers::getEngineerByTokenWx($token);
            if(is_numeric($engineer_data) && $engineer_data < 0){
                $response = Lang::get("sce_error.user_token_not_exist_1004");
                break;
            }
            $wxp = WeiXinPay::leftJoin('car_wash_order','weixin_pay.order_id','=','car_wash_order.order_id')
                ->where('weixin_pay.status',0)
                ->where('car_wash_order.shop_id',$engineer_data->type_id)
                ->select('weixin_pay.pay_url','weixin_pay.order_type','weixin_pay.order_id','car_wash_order.car_no','car_wash_order.pay_amount')
                ->get();
            foreach($wxp as $_w){
                $_w->pay_amount=bcdiv($_w->pay_amount,100,2);
            }
            $result = array(
                'wx_pay_list'=> $wxp
            );
            $response = array('code' => 0, 'msg' => 'ok', 'result' => $result);
        } while (false);
        Log::info("info", array("system" => "sce" ,"event" => "wx_pay_list", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
}